package cn.wolfcode.crm.service.imp;

import cn.wolfcode.crm.domain.SystemLog;
import cn.wolfcode.crm.mapper.SystemLogMapper;
import cn.wolfcode.crm.service.ISystemLogService;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.query.QueryObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class SystemLogServiceImpl implements ISystemLogService {
    @Autowired
    private SystemLogMapper systemLogMapper;


    public void delete(Long id) {
        systemLogMapper.deleteByPrimaryKey(id);
    }

    public SystemLog selectByPrimaryKey(Long id) {
        return systemLogMapper.selectByPrimaryKey(id);
    }

    public List<SystemLog> selectAll() {
        return systemLogMapper.selectAll();
    }


    public PageResult query(QueryObject qo) {
        int total = systemLogMapper.selectCount(qo);
        if(total==0){
            return new PageResult(total, Collections.EMPTY_LIST);
        }
        List<SystemLog> rows = systemLogMapper.queryForList(qo);
        rows.forEach(System.out::println);
        return new PageResult(total,rows);
    }

    public void insert(SystemLog systemLog) {
        systemLogMapper.insert(systemLog);
    }


    public void saveOrUpdate(SystemLog systemLog) {

        if (systemLog.getId() == null) {
            systemLogMapper.insert(systemLog);
        }else{
            systemLogMapper.updateByPrimaryKey(systemLog);
        }
    }
}
